package apiPractice;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class Test07 {
    public static void main(String[] args) throws IOException {
        //统计一个文件calcCharNum.txt（自己先往里面写一些内容）
        //中各个字母出现次数
        /*Map<Character,Integer> map = new HashMap<>();
        map.containsKey()*/
        FileOutputStream fos = new FileOutputStream("calcCharNum.txt");
        FileInputStream fis = new FileInputStream("calcCharNum.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        osw.write("sadsadwfsadwASDSADAASDwdsadwa");
        osw.close();
        int d;
        int times = 0;
        String s = "";
        while ((d = isr.read()) != -1) {
            System.out.print((char) d);
            s += String.valueOf((char) d);
        }
        System.out.println();

        int[] count = new int[s.length()];//每个字符出现的次数
        String b = new String();//用于存储不重复的字符
        for (int i = 0; i <s.length() ; i++) {
            if (!b.contains(String.valueOf(s.charAt(i)))){//判断是否没有出现相同的字符
                b+=String.valueOf(s.charAt(i));//若没有重复则放入到b字符串里

            }else {
                for (int j = 0; j <b.length() ; j++) {//遍历b中不重复的字符
                    if (s.charAt(i)==b.charAt(j)){//判断原字符是否于当前字符相等,若相等则对应下标+1
                        count[j]++;
                    }
                }
            }
        }
        for (int i = 0; i <b.length() ; i++) {
            System.out.println(b.charAt(i)+"出现的次数"+(count[i]+1));
        }
        isr.close();
    }
}


///自己做不出来,只能百度

